<div id = 'MetaSeoPreview'>
	<dl class = 'seo_bar'>
		<dt>SEO优化</dt>
		<dd style = 'text-align:center'>
			<a class = 'handel' href = 'javascript:;' onclick = 'SM.preview()'>添加</a>
			<a class = 'handel-close' style = 'display:none' href = 'javascript:;' onclick = 'SM.unpreview()'>关闭</a>
		</dd>
	</dl>
	<div id = 'seo_meta_config'>
	
	</div>
</div>
<?php 
echo $this->Form->input('sys_seo_id',array('id'=>'SeoMetaIdForPlugin','type'=>'hidden'));
?>
<script>
jQuery(function(){
	SM.init();
});
SM = {};
SM.id = false;
SM.init = function(){
	SM.getId();
	if(SM.id){
		$('#MetaSeoPreview .seo_bar .handel').html('编辑');
	}
};
SM.getId = function(){
	var tag = $('#SeoMetaIdForPlugin').val();
	SM.id = tag?tag:false;
};
SM.setId = function(id){
	SM.id = id;
	$('#SeoMetaIdForPlugin').val(id);
};
SM.unpreview = function(){
	$('#seo_meta_config').html('');
}
SM.preview = function(){
	$('#MetaSeoPreview .seo_bar .handel-close').show();
	var action = GM.RootScript+'admin/seo_meta/SeoMeta/innerConfig/'+SM.id;
	var data = false;//{"data[SeoMeta][id]":GM.id};
	var callback = function(res){
		if(res.state){
			$('#seo_meta_config').html(res.html);
		}else{
			
		}
	}
	SM.action(action,data,callback);
};
SM.config = function(){
	var action = GM.RootScript+'admin/seo_meta/SeoMeta/innerConfig/'+SM.id;
	var data = SM.serializeObject ('#seo_meta_config');
//	console.log(data);
	var callback = function(res){
		$('#seo_meta_config').html(res.html);
		if(res.state){
			SM.setId(res.data);
		}
	}
	SM.action(action,data,callback);
};
SM.serializeObject = function(tarStr){
	var o = {};
	jQuery('input',jQuery(tarStr)).each(function(){
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
				o[this.name] = this.value || '';
		}
	});
	return o;
}
SM.action = function(action,data,callback){
	method = data?'Post':'Get';
	jQuery.ajax({
		type:method,
		url:action,
		data:data,
		dataType:'json',
		success : function(data){
			callback(data)
		},
		error : function(e){
			alert(e);
		},
		complete:function(){
		}
	});
}
</script>
<style>
#MetaSeoPreview {width:100%;border:1px solid #ccc}
#MetaSeoPreview dl {height:30px;border-bottom:1px solid #ccc;}
#MetaSeoPreview dt {width:20%;float:left;border-right:1px solid #ccc; line-height:30px;text-align:center;font-weight:bold}
#MetaSeoPreview dd {width:75%;float:left;line-height:30px;text-align:left}
#MetaSeoPreview dd input{width:70%}
#MetaSeoPreview .error-message{display:inline}
</style>